/*==========================payInfo和setting 相关接口==============================*/
import Ajax from './apiAjax';
export  default {
  state:{
    oPayInfo:null, //支付基本信息
    oInitEditPayInfo:null, //编辑支付信息初始化
    oInitWithHolding:null,
    oInitEditPaySchedule:null, //pay schedule 初始化
    oInitEditPayItem:null, // howMuch 初始化
    oInitAddDeduction:null, //添加Deduction 初始化
    oInitPayChester:null,
    personTaxInfo:null,
    payPeriod:null,
    editModel:null,
    payChecks:{
      pb:null,
      list:null,
    },
    personPayChecks:{
      pb:null,
      list:null,
    },
    payCheckDetail:null,
  },
  mutations:{
    setCommonStateData(state,{key,data}){
      state[key] = data;
    }
  },
  actions:{
    /**
     *获取员工的支付基本数据
     * @param commit
     * @param paramData eg...{personId:123}
     * @returns {Promise}
     */
    getPayInfo({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/pay/getPayInfo',
          data:paramData,
          success:function (data) {
            commit('setCommonStateData',{key:'oPayInfo',data:data.data});
            resolve();
          }
        })
      })
    },
    /**
     * 获取编辑支付的初始化数据
     * @param commit
     * @param paramData eg...{personId:123}
     * @returns {Promise}
     */
    initEditPayInfo({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/pay/editPayInfo',
          data:paramData,
          success:function (data) {
            commit('setCommonStateData',{key:'oInitEditPayInfo',data:data.data});
            resolve();
          }
        })
      })
    },
    /**
     * 保存 payInfo
     * @param commit
     * @param paramData eg...{personId:123}
     * @returns {Promise}
     */
    savePayInfo({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/pay/savePayInfo',
          data:paramData,
          success:function (data) {
            commit('setCommonStateData',{key:'oInitEditPayInfo',data:data.data});
            resolve();
          }
        })
      })
    },
    getPersonTaxInfo({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/personInfo/getPersonTaxInfo',
          data:paramData,
          success:function (data) {
           commit('setCommonStateData',{key:'personTaxInfo',data:data.data});
            resolve();
          }
        })
      })
    },
    modifyPersonTaxInfo({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/personInfo/modifyPersonTaxInfo',
          data:JSON.stringify(paramData),
          contentType: "application/json;charset=UTF-8",
          success:function (data) {
            resolve();
          }
        })
      })
    },
    /**
     * 获取编辑howOften Schedule 初始化数据
     * @param commit
     * @param paramData eg...{personId:123}
     * @returns {Promise}
     */
    initEditPaySchedule({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/payschedule/addPayScheduleInit',
          data:paramData,
          success:function (data) {
            commit('setCommonStateData',{key:'oInitEditPaySchedule',data:data.data});
            resolve();
          }
        })
      })
    },
    /**
     * 保存 schedule
     * @param commit
     * @param paramData
     * @returns {Promise}
     */
    savePaySchedule({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/payschedule/addPaySchedule',
          data:paramData,
          success:function (data) {
            resolve();
          }
        })
      })
    },
    /***
     * 查询发薪日程的发薪周期
     * @param.option
     * */
    getPayPeriod:({commit},paramData) => {
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/payschedule/queryPayPeriod',
          data:paramData,
          success:function (data) {
            commit('setCommonStateData',{key:'payPeriod',data:data.data.payPeriod});
            resolve();
          }
        })
      })
    },
    /**
     * 获取编辑howMuch  初始化数据
     * @param commit
     * @param paramData eg...{personId:123}
     * @returns {Promise}
     */
    initEditPayItem({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/pay/editPayItem',
          data:paramData,
          success:function (data) {
            commit('setCommonStateData',{key:'oInitEditPayItem',data:data.data});
            resolve();
          }
        })
      })
    },
    /**
     * 获取编辑howMuch  update
     * @param commit
     * @param paramData
     * @returns {Promise}
     */
    updatePayItem({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/pay/modifyPayItem',
          data:paramData,
          success:function (data) {
            resolve();
          }
        })
      })
    },
    /**
     * 获取 addDeductions 初始化数据
     * @param commit
     * @param paramData eg...{personId:123}
     * @returns {Promise}
     */
    initAddDeduction({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/deduction/init',
          data:paramData,
          success:function (data) {
            commit('setCommonStateData',{key:'oInitAddDeduction',data:data.data});
            resolve();
          }
        })
      })
    },
    saveDeduction({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/deduction/save',
          data:paramData,
          success:function (data) {
            resolve();
          }
        })
      })
    },
    getPayCheckList({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/pay/queryPayCheckList',
          data:paramData,
          success:function (data) {
            if(paramData.personId){
              commit('setCommonStateData',{key:'personPayChecks',data:{pb:data.pb,list:data.data.payCheckList}});
            }else{
              commit('setCommonStateData',{key:'payChecks',data:{pb:data.pb,list:data.data.payCheckList}});
            }
            resolve();
          }
        })
      })
    },
    getPayCheckDetail({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/pay/payCheckDetail',
          data:paramData,
          success:function (data) {
              commit('setCommonStateData',{key:'payCheckDetail',data:data.data});
            resolve();
          }
        })
      })
    },
  },
  getters: {
    oPayInfo: (state, getters) => {
      return state.oPayInfo;
    },
    oEditPayInfo: (state, getters) => {
      return state.oInitEditPayInfo;
    },
    oInitEditPaySchedule: (state, getters) => {
      return state.oInitEditPaySchedule;
    },
    oInitEditPayItem: (state, getters) => {
      return state.oInitEditPayItem;
    },
    oInitAddDeduction: (state, getters) => {
      return state.oInitAddDeduction;
    },
    personTaxInfo: (state, getters) => {
      return state.personTaxInfo;
    },
    payPeriod: (state, getters) => {
      return state.payPeriod;
    },
    editModel: (state, getters) => {
      return state.editModel;
    },
    payCheckList: (state, getters) => {
      return state.payChecks.list;
    },
    payCheckListPb: (state, getters) => {
      return state.payChecks.pb;
    },
    personPayCheckList: (state, getters) => {
      return state.personPayChecks.list;
    },
    personPayCheckListPb: (state, getters) => {
      return state.personPayChecks.pb;
    },
    payCheckDetail: (state, getters) => {
      return state.payCheckDetail;
    },
  }
}
